home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Actual 85 Febrero 2004.iso / Experto / Apache / apache_2.0.48-win32-x86-no_ssl.msi / Data.Cab / F251761_apr_pools.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-09-26  |  25.5 KB  |  703 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_POOLS_H
  56. #define APR_POOLS_H
  57.  
  58. /**
  59.  * @file apr_pools.h
  60.  * @brief APR memory allocation
  61.  *
  62.  * Resource allocation routines...
  63.  *
  64.  * designed so that we don't have to keep track of EVERYTHING so that
  65.  * it can be explicitly freed later (a fundamentally unsound strategy ---
  66.  * particularly in the presence of die()).
  67.  *
  68.  * Instead, we maintain pools, and allocate items (both memory and I/O
  69.  * handlers) from the pools --- currently there are two, one for per
  70.  * transaction info, and one for config info.  When a transaction is over,
  71.  * we can delete everything in the per-transaction apr_pool_t without fear,
  72.  * and without thinking too hard about it either.
  73.  */
  74.  
  75. #include "apr.h"
  76. #include "apr_errno.h"
  77. #include "apr_general.h" /* for APR_STRINGIFY */
  78. #define APR_WANT_MEMFUNC /**< for no good reason? */
  79. #include "apr_want.h"
  80.  
  81. #ifdef __cplusplus
  82. extern "C" {
  83. #endif
  84.  
  85. /**
  86.  * @defgroup apr_pools Memory Pool Functions
  87.  * @ingroup APR 
  88.  * @{
  89.  */
  90.  
  91. /** The fundamental pool type */
  92. typedef struct apr_pool_t apr_pool_t;
  93.  
  94.  
  95. /**
  96.  * Declaration helper macro to construct apr_foo_pool_get()s.
  97.  *
  98.  * This standardized macro is used by opaque (APR) data types to return
  99.  * the apr_pool_t that is associated with the data type.
  100.  *
  101.  * APR_POOL_DECLARE_ACCESSOR() is used in a header file to declare the
  102.  * accessor function. A typical usage and result would be:
  103.  * <pre>
  104.  *    APR_POOL_DECLARE_ACCESSOR(file);
  105.  * becomes:
  106.  *    APR_DECLARE(apr_pool_t *) apr_file_pool_get(apr_file_t *ob);
  107.  * </pre>
  108.  * @remark Doxygen unwraps this macro (via doxygen.conf) to provide 
  109.  * actual help for each specific occurance of apr_foo_pool_get.
  110.  * @remark the linkage is specified for APR. It would be possible to expand
  111.  *       the macros to support other linkages.
  112.  */
  113. #define APR_POOL_DECLARE_ACCESSOR(type) \
  114.     APR_DECLARE(apr_pool_t *) apr_##type##_pool_get \
  115.         (const apr_##type##_t *the##type)
  116.  
  117. /** 
  118.  * Implementation helper macro to provide apr_foo_pool_get()s.
  119.  *
  120.  * In the implementation, the APR_POOL_IMPLEMENT_ACCESSOR() is used to
  121.  * actually define the function. It assumes the field is named "pool".
  122.  */
  123. #define APR_POOL_IMPLEMENT_ACCESSOR(type) \
  124.     APR_DECLARE(apr_pool_t *) apr_##type##_pool_get \
  125.             (const apr_##type##_t *the##type) \
  126.         { return the##type->pool; }
  127.  
  128.  
  129. /**
  130.  * Pool debug levels
  131.  *
  132.  * <pre>
  133.  * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  134.  * ---------------------------------
  135.  * |   |   |   |   |   |   |   | x |  General debug code enabled (usefull in
  136.  *                                    combination with --with-efence).
  137.  *
  138.  * |   |   |   |   |   |   | x |   |  Verbose output on stderr (report
  139.  *                                    CREATE, CLEAR, DESTROY).
  140.  *
  141.  * |   |   |   | x |   |   |   |   |  Verbose output on stderr (report
  142.  *                                    PALLOC, PCALLOC).
  143.  *
  144.  * |   |   |   |   |   | x |   |   |  Lifetime checking. On each use of a
  145.  *                                    pool, check its lifetime.  If the pool
  146.  *                                    is out of scope, abort().
  147.  *                                    In combination with the verbose flag
  148.  *                                    above, it will output LIFE in such an
  149.  *                                    event prior to aborting.
  150.  *
  151.  * |   |   |   |   | x |   |   |   |  Pool owner checking.  On each use of a
  152.  *                                    pool, check if the current thread is the
  153.  *                                    pools owner.  If not, abort().  In
  154.  *                                    combination with the verbose flag above,
  155.  *                                    it will output OWNER in such an event
  156.  *                                    prior to aborting.  Use the debug
  157.  *                                    function apr_pool_owner_set() to switch
  158.  *                                    a pools ownership.
  159.  *
  160.  * When no debug level was specified, assume general debug mode.
  161.  * If level 0 was specified, debugging is switched off
  162.  * </pre>
  163.  */
  164. #if defined(APR_POOL_DEBUG)
  165. #if (APR_POOL_DEBUG != 0) && (APR_POOL_DEBUG - 0 == 0)
  166. #undef APR_POOL_DEBUG
  167. #define APR_POOL_DEBUG 1
  168. #endif
  169. #else
  170. #define APR_POOL_DEBUG 0
  171. #endif
  172.  
  173. /** the place in the code where the particular function was called */
  174. #define APR_POOL__FILE_LINE__ __FILE__ ":" APR_STRINGIFY(__LINE__)
  175.  
  176.  
  177.  
  178. /** A function that is called when allocation fails. */
  179. typedef int (*apr_abortfunc_t)(int retcode);
  180.  
  181. /*
  182.  * APR memory structure manipulators (pools, tables, and arrays).
  183.  */
  184.  
  185. /*
  186.  * Initialization
  187.  */
  188.  
  189. /**
  190.  * Setup all of the internal structures required to use pools
  191.  * @remark Programs do NOT need to call this directly.  APR will call this
  192.  *      automatically from apr_initialize.
  193.  * @internal
  194.  */
  195. APR_DECLARE(apr_status_t) apr_pool_initialize(void);
  196.  
  197. /**
  198.  * Tear down all of the internal structures required to use pools
  199.  * @remark Programs do NOT need to call this directly.  APR will call this
  200.  *      automatically from apr_terminate.
  201.  * @internal
  202.  */
  203. APR_DECLARE(void) apr_pool_terminate(void);
  204.  
  205.  
  206. /*
  207.  * Pool creation/destruction
  208.  */
  209.  
  210. #include "apr_allocator.h"
  211.  
  212. /**
  213.  * Create a new pool.
  214.  * @param newpool The pool we have just created.
  215.  * @param parent The parent pool.  If this is NULL, the new pool is a root
  216.  *        pool.  If it is non-NULL, the new pool will inherit all
  217.  *        of its parent pool's attributes, except the apr_pool_t will
  218.  *        be a sub-pool.
  219.  * @param abort_fn A function to use if the pool cannot allocate more memory.
  220.  * @param allocator The allocator to use with the new pool.  If NULL the
  221.  *        allocator of the parent pool will be used.
  222.  */
  223. APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,
  224.                                              apr_pool_t *parent,
  225.                                              apr_abortfunc_t abort_fn,
  226.                                              apr_allocator_t *allocator);
  227.  
  228. /**
  229.  * Debug version of apr_pool_create_ex.
  230.  * @param newpool @see apr_pool_create.
  231.  * @param parent @see apr_pool_create.
  232.  * @param abort_fn @see apr_pool_create.
  233.  * @param allocator @see apr_pool_create.
  234.  * @param file_line Where the function is called from.
  235.  *        This is usually APR_POOL__FILE_LINE__.
  236.  * @remark Only available when APR_POOL_DEBUG is defined.
  237.  *         Call this directly if you have you apr_pool_create_ex
  238.  *         calls in a wrapper function and wish to override
  239.  *         the file_line argument to reflect the caller of
  240.  *         your wrapper function.  If you do not have
  241.  *         apr_pool_create_ex in a wrapper, trust the macro
  242.  *         and don't call apr_pool_create_ex_debug directly.
  243.  */
  244. APR_DECLARE(apr_status_t) apr_pool_create_ex_debug(apr_pool_t **newpool,
  245.                                                    apr_pool_t *parent,
  246.                                                    apr_abortfunc_t abort_fn,
  247.                                                    apr_allocator_t *allocator,
  248.                                                    const char *file_line);
  249.  
  250. #if APR_POOL_DEBUG
  251. #define apr_pool_create_ex(newpool, parent, abort_fn, allocator)  \
  252.     apr_pool_create_ex_debug(newpool, parent, abort_fn, allocator, \
  253.                              APR_POOL__FILE_LINE__)
  254. #endif
  255.  
  256. /**
  257.  * Create a new pool.
  258.  * @param newpool The pool we have just created.
  259.  * @param parent The parent pool.  If this is NULL, the new pool is a root
  260.  *        pool.  If it is non-NULL, the new pool will inherit all
  261.  *        of its parent pool's attributes, except the apr_pool_t will
  262.  *        be a sub-pool.
  263.  */
  264. #if defined(DOXYGEN)
  265. APR_DECLARE(apr_status_t) apr_pool_create(apr_pool_t **newpool,
  266.                                           apr_pool_t *parent);
  267. #else
  268. #if APR_POOL_DEBUG
  269. #define apr_pool_create(newpool, parent) \
  270.     apr_pool_create_ex_debug(newpool, parent, NULL, NULL, \
  271.                              APR_POOL__FILE_LINE__)
  272. #else
  273. #define apr_pool_create(newpool, parent) \
  274.     apr_pool_create_ex(newpool, parent, NULL, NULL)
  275. #endif
  276. #endif
  277.  
  278. /** @deprecated @see apr_pool_create_ex */
  279. #if APR_POOL_DEBUG
  280. #define apr_pool_sub_make(newpool, parent, abort_fn) \
  281.     (void)apr_pool_create_ex_debug(newpool, parent, abort_fn, \
  282.                                    NULL, \
  283.                                    APR_POOL__FILE_LINE__)
  284. #else
  285. #define apr_pool_sub_make(newpool, parent, abort_fn) \
  286.     (void)apr_pool_create_ex(newpool, parent, abort_fn, NULL)
  287. #endif
  288.  
  289. /**
  290.  * Find the pools allocator
  291.  * @param pool The pool to get the allocator from.
  292.  */
  293. APR_DECLARE(apr_allocator_t *) apr_pool_allocator_get(apr_pool_t *pool);
  294.  
  295. /**
  296.  * Clear all memory in the pool and run all the cleanups. This also destroys all
  297.  * subpools.
  298.  * @param p The pool to clear
  299.  * @remark This does not actually free the memory, it just allows the pool
  300.  *         to re-use this memory for the next allocation.
  301.  * @see apr_pool_destroy()
  302.  */
  303. APR_DECLARE(void) apr_pool_clear(apr_pool_t *p);
  304.  
  305. /**
  306.  * Debug version of apr_pool_clear.
  307.  * @param p See: apr_pool_clear.
  308.  * @param file_line Where the function is called from.
  309.  *        This is usually APR_POOL__FILE_LINE__.
  310.  * @remark Only available when APR_POOL_DEBUG is defined.
  311.  *         Call this directly if you have you apr_pool_clear
  312.  *         calls in a wrapper function and wish to override
  313.  *         the file_line argument to reflect the caller of
  314.  *         your wrapper function.  If you do not have
  315.  *         apr_pool_clear in a wrapper, trust the macro
  316.  *         and don't call apr_pool_destroy_clear directly.
  317.  */
  318. APR_DECLARE(void) apr_pool_clear_debug(apr_pool_t *p,
  319.                                        const char *file_line);
  320.  
  321. #if APR_POOL_DEBUG
  322. #define apr_pool_clear(p) \
  323.     apr_pool_clear_debug(p, APR_POOL__FILE_LINE__)
  324. #endif
  325.  
  326. /**
  327.  * Destroy the pool. This takes similar action as apr_pool_clear() and then
  328.  * frees all the memory.
  329.  * @param p The pool to destroy
  330.  * @remark This will actually free the memory
  331.  */
  332. APR_DECLARE(void) apr_pool_destroy(apr_pool_t *p);
  333.  
  334. /**
  335.  * Debug version of apr_pool_destroy.
  336.  * @param p See: apr_pool_destroy.
  337.  * @param file_line Where the function is called from.
  338.  *        This is usually APR_POOL__FILE_LINE__.
  339.  * @remark Only available when APR_POOL_DEBUG is defined.
  340.  *         Call this directly if you have you apr_pool_destroy
  341.  *         calls in a wrapper function and wish to override
  342.  *         the file_line argument to reflect the caller of
  343.  *         your wrapper function.  If you do not have
  344.  *         apr_pool_destroy in a wrapper, trust the macro
  345.  *         and don't call apr_pool_destroy_debug directly.
  346.  */
  347. APR_DECLARE(void) apr_pool_destroy_debug(apr_pool_t *p,
  348.                                          const char *file_line);
  349.  
  350. #if APR_POOL_DEBUG
  351. #define apr_pool_destroy(p) \
  352.     apr_pool_destroy_debug(p, APR_POOL__FILE_LINE__)
  353. #endif
  354.  
  355.  
  356. /*
  357.  * Memory allocation
  358.  */
  359.  
  360. /**
  361.  * Allocate a block of memory from a pool
  362.  * @param p The pool to allocate from
  363.  * @param size The amount of memory to allocate
  364.  * @return The allocated memory
  365.  */
  366. APR_DECLARE(void *) apr_palloc(apr_pool_t *p, apr_size_t size);
  367.  
  368. /**
  369.  * Debug version of apr_palloc
  370.  * @param p See: apr_palloc
  371.  * @param size See: apr_palloc
  372.  * @param file_line Where the function is called from.
  373.  *        This is usually APR_POOL__FILE_LINE__.
  374.  * @return See: apr_palloc
  375.  */
  376. APR_DECLARE(void *) apr_palloc_debug(apr_pool_t *p, apr_size_t size,
  377.                                      const char *file_line);
  378.  
  379. #if APR_POOL_DEBUG
  380. #define apr_palloc(p, size) \
  381.     apr_palloc_debug(p, size, APR_POOL__FILE_LINE__)
  382. #endif
  383.  
  384. /**
  385.  * Allocate a block of memory from a pool and set all of the memory to 0
  386.  * @param p The pool to allocate from
  387.  * @param size The amount of memory to allocate
  388.  * @return The allocated memory
  389.  */
  390. #if defined(DOXYGEN)
  391. APR_DECLARE(void *) apr_pcalloc(apr_pool_t *p, apr_size_t size);
  392. #elif !APR_POOL_DEBUG
  393. #define apr_pcalloc(p, size) memset(apr_palloc(p, size), 0, size)
  394. #endif
  395.  
  396. /**
  397.  * Debug version of apr_pcalloc
  398.  * @param p See: apr_pcalloc
  399.  * @param size See: apr_pcalloc
  400.  * @param file_line Where the function is called from.
  401.  *        This is usually APR_POOL__FILE_LINE__.
  402.  * @return See: apr_pcalloc
  403.  */
  404. APR_DECLARE(void *) apr_pcalloc_debug(apr_pool_t *p, apr_size_t size,
  405.                                       const char *file_line);
  406.  
  407. #if APR_POOL_DEBUG
  408. #define apr_pcalloc(p, size) \
  409.     apr_pcalloc_debug(p, size, APR_POOL__FILE_LINE__)
  410. #endif
  411.  
  412.  
  413. /*
  414.  * Pool Properties
  415.  */
  416.  
  417. /**
  418.  * Set the function to be called when an allocation failure occurs.
  419.  * @remark If the program wants APR to exit on a memory allocation error,
  420.  *      then this function can be called to set the callback to use (for
  421.  *      performing cleanup and then exiting). If this function is not called,
  422.  *      then APR will return an error and expect the calling program to
  423.  *      deal with the error accordingly.
  424.  */
  425. APR_DECLARE(void) apr_pool_abort_set(apr_abortfunc_t abortfunc,
  426.                                      apr_pool_t *pool);
  427.  
  428. /** @deprecated @see apr_pool_abort_set */
  429. APR_DECLARE(void) apr_pool_set_abort(apr_abortfunc_t abortfunc,
  430.                                      apr_pool_t *pool);
  431.  
  432. /**
  433.  * Get the abort function associated with the specified pool.
  434.  * @param pool The pool for retrieving the abort function.
  435.  * @return The abort function for the given pool.
  436.  */
  437. APR_DECLARE(apr_abortfunc_t) apr_pool_abort_get(apr_pool_t *pool);
  438.  
  439. /** @deprecated @see apr_pool_abort_get */
  440. APR_DECLARE(apr_abortfunc_t) apr_pool_get_abort(apr_pool_t *pool);
  441.  
  442. /**
  443.  * Get the parent pool of the specified pool.
  444.  * @param pool The pool for retrieving the parent pool.
  445.  * @return The parent of the given pool.
  446.  */
  447. APR_DECLARE(apr_pool_t *) apr_pool_parent_get(apr_pool_t *pool);
  448.  
  449. /** @deprecated @see apr_pool_parent_get */
  450. APR_DECLARE(apr_pool_t *) apr_pool_get_parent(apr_pool_t *pool);
  451.  
  452. /**
  453.  * Determine if pool a is an ancestor of pool b
  454.  * @param a The pool to search
  455.  * @param b The pool to search for
  456.  * @return True if a is an ancestor of b, NULL is considered an ancestor
  457.  *         of all pools.
  458.  */
  459. APR_DECLARE(int) apr_pool_is_ancestor(apr_pool_t *a, apr_pool_t *b);
  460.  
  461. /**
  462.  * Tag a pool (give it a name)
  463.  * @param pool The pool to tag
  464.  * @param tag  The tag
  465.  */
  466. APR_DECLARE(void) apr_pool_tag(apr_pool_t *pool, const char *tag);
  467.  
  468.  
  469. /*
  470.  * User data management
  471.  */
  472.  
  473. /**
  474.  * Set the data associated with the current pool
  475.  * @param data The user data associated with the pool.
  476.  * @param key The key to use for association
  477.  * @param cleanup The cleanup program to use to cleanup the data (NULL if none)
  478.  * @param pool The current pool
  479.  * @warning The data to be attached to the pool should have a life span
  480.  *          at least as long as the pool it is being attached to.
  481.  *
  482.  *      Users of APR must take EXTREME care when choosing a key to
  483.  *      use for their data.  It is possible to accidentally overwrite
  484.  *      data by choosing a key that another part of the program is using.
  485.  *      Therefore it is advised that steps are taken to ensure that unique
  486.  *      keys are used for all of the userdata objects in a particular pool
  487.  *      (the same key in two different pools or a pool and one of its
  488.  *      subpools is okay) at all times.  Careful namespace prefixing of
  489.  *      key names is a typical way to help ensure this uniqueness.
  490.  */
  491. APR_DECLARE(apr_status_t) apr_pool_userdata_set(
  492.     const void *data,
  493.     const char *key,
  494.     apr_status_t (*cleanup)(void *),
  495.     apr_pool_t *pool);
  496.  
  497. /**
  498.  * Set the data associated with the current pool
  499.  * @param data The user data associated with the pool.
  500.  * @param key The key to use for association
  501.  * @param cleanup The cleanup program to use to cleanup the data (NULL if none)
  502.  * @param pool The current pool
  503.  * @note same as apr_pool_userdata_set(), except that this version doesn't
  504.  *       make a copy of the key (this function is useful, for example, when
  505.  *       the key is a string literal)
  506.  * @warning This should NOT be used if the key could change addresses by
  507.  *       any means between the apr_pool_userdata_setn() call and a
  508.  *       subsequent apr_pool_userdata_get() on that key, such as if a
  509.  *       static string is used as a userdata key in a DSO and the DSO could
  510.  *       be unloaded and reloaded between the _setn() and the _get().  You
  511.  *       MUST use apr_pool_userdata_set() in such cases.
  512.  * @warning More generally, the key and the data to be attached to the
  513.  *       pool should have a life span at least as long as the pool itself.
  514.  *
  515.  */
  516. APR_DECLARE(apr_status_t) apr_pool_userdata_setn(
  517.     const void *data,
  518.     const char *key,
  519.     apr_status_t (*cleanup)(void *),
  520.     apr_pool_t *pool);
  521.  
  522. /**
  523.  * Return the data associated with the current pool.
  524.  * @param data The user data associated with the pool.
  525.  * @param key The key for the data to retrieve
  526.  * @param pool The current pool.
  527.  */
  528. APR_DECLARE(apr_status_t) apr_pool_userdata_get(void **data, const char *key,
  529.                                                 apr_pool_t *pool);
  530.  
  531.  
  532. /*
  533.  * Cleanup
  534.  *
  535.  * Cleanups are performed in the reverse order they were registered.  That is:
  536.  * Last In, First Out.
  537.  */
  538.  
  539. /**
  540.  * Register a function to be called when a pool is cleared or destroyed
  541.  * @param p The pool register the cleanup with
  542.  * @param data The data to pass to the cleanup function.
  543.  * @param plain_cleanup The function to call when the pool is cleared
  544.  *                      or destroyed
  545.  * @param child_cleanup The function to call when a child process is being
  546.  *                      shutdown - this function is called in the child, obviously!
  547.  */
  548. APR_DECLARE(void) apr_pool_cleanup_register(
  549.     apr_pool_t *p,
  550.     const void *data,
  551.     apr_status_t (*plain_cleanup)(void *),
  552.     apr_status_t (*child_cleanup)(void *));
  553.  
  554. /**
  555.  * Remove a previously registered cleanup function
  556.  * @param p The pool remove the cleanup from
  557.  * @param data The data to remove from cleanup
  558.  * @param cleanup The function to remove from cleanup
  559.  * @remarks For some strange reason only the plain_cleanup is handled by this
  560.  *          function
  561.  */
  562. APR_DECLARE(void) apr_pool_cleanup_kill(apr_pool_t *p, const void *data,
  563.                                         apr_status_t (*cleanup)(void *));
  564.  
  565. /**
  566.  * Replace the child cleanup of a previously registered cleanup
  567.  * @param p The pool of the registered cleanup
  568.  * @param data The data of the registered cleanup
  569.  * @param plain_cleanup The plain cleanup function of the registered cleanup
  570.  * @param child_cleanup The function to register as the child cleanup
  571.  */
  572. APR_DECLARE(void) apr_pool_child_cleanup_set(
  573.     apr_pool_t *p,
  574.     const void *data,
  575.     apr_status_t (*plain_cleanup)(void *),
  576.     apr_status_t (*child_cleanup)(void *));
  577.  
  578. /**
  579.  * Run the specified cleanup function immediately and unregister it. Use
  580.  * @a data instead of the data that was registered with the cleanup.
  581.  * @param p The pool remove the cleanup from
  582.  * @param data The data to remove from cleanup
  583.  * @param cleanup The function to remove from cleanup
  584.  */
  585. APR_DECLARE(apr_status_t) apr_pool_cleanup_run(
  586.     apr_pool_t *p,
  587.     void *data,
  588.     apr_status_t (*cleanup)(void *));
  589.  
  590. /**
  591.  * An empty cleanup function
  592.  * @param data The data to cleanup
  593.  */
  594. APR_DECLARE_NONSTD(apr_status_t) apr_pool_cleanup_null(void *data);
  595.  
  596. /* Preparing for exec() --- close files, etc., but *don't* flush I/O
  597.  * buffers, *don't* wait for subprocesses, and *don't* free any memory.
  598.  */
  599. /**
  600.  * Run all of the child_cleanups, so that any unnecessary files are
  601.  * closed because we are about to exec a new program
  602.  */
  603. APR_DECLARE(void) apr_pool_cleanup_for_exec(void);
  604.  
  605.  
  606. /**
  607.  * @defgroup PoolDebug Pool Debugging functions.
  608.  *
  609.  * pools have nested lifetimes -- sub_pools are destroyed when the
  610.  * parent pool is cleared.  We allow certain liberties with operations
  611.  * on things such as tables (and on other structures in a more general
  612.  * sense) where we allow the caller to insert values into a table which
  613.  * were not allocated from the table's pool.  The table's data will
  614.  * remain valid as long as all the pools from which its values are
  615.  * allocated remain valid.
  616.  *
  617.  * For example, if B is a sub pool of A, and you build a table T in
  618.  * pool B, then it's safe to insert data allocated in A or B into T
  619.  * (because B lives at most as long as A does, and T is destroyed when
  620.  * B is cleared/destroyed).  On the other hand, if S is a table in
  621.  * pool A, it is safe to insert data allocated in A into S, but it
  622.  * is *not safe* to insert data allocated from B into S... because
  623.  * B can be cleared/destroyed before A is (which would leave dangling
  624.  * pointers in T's data structures).
  625.  *
  626.  * In general we say that it is safe to insert data into a table T
  627.  * if the data is allocated in any ancestor of T's pool.  This is the
  628.  * basis on which the APR_POOL_DEBUG code works -- it tests these ancestor
  629.  * relationships for all data inserted into tables.  APR_POOL_DEBUG also
  630.  * provides tools (apr_pool_find, and apr_pool_is_ancestor) for other
  631.  * folks to implement similar restrictions for their own data
  632.  * structures.
  633.  *
  634.  * However, sometimes this ancestor requirement is inconvenient --
  635.  * sometimes we're forced to create a sub pool (such as through
  636.  * apr_sub_req_lookup_uri), and the sub pool is guaranteed to have
  637.  * the same lifetime as the parent pool.  This is a guarantee implemented
  638.  * by the *caller*, not by the pool code.  That is, the caller guarantees
  639.  * they won't destroy the sub pool individually prior to destroying the
  640.  * parent pool.
  641.  *
  642.  * In this case the caller must call apr_pool_join() to indicate this
  643.  * guarantee to the APR_POOL_DEBUG code.  There are a few examples spread
  644.  * through the standard modules.
  645.  *
  646.  * These functions are only implemented when #APR_POOL_DEBUG is set.
  647.  *
  648.  * @{
  649.  */
  650. #if APR_POOL_DEBUG || defined(DOXYGEN)
  651. /**
  652.  * Guarantee that a subpool has the same lifetime as the parent.
  653.  * @param p The parent pool
  654.  * @param sub The subpool
  655.  */
  656. APR_DECLARE(void) apr_pool_join(apr_pool_t *p, apr_pool_t *sub);
  657.  
  658. /**
  659.  * Find a pool from something allocated in it.
  660.  * @param mem The thing allocated in the pool
  661.  * @return The pool it is allocated in
  662.  */
  663. APR_DECLARE(apr_pool_t *) apr_pool_find(const void *mem);
  664.  
  665. /**
  666.  * Report the number of bytes currently in the pool
  667.  * @param p The pool to inspect
  668.  * @param recurse Recurse/include the subpools' sizes
  669.  * @return The number of bytes
  670.  */
  671. APR_DECLARE(apr_size_t) apr_pool_num_bytes(apr_pool_t *p, int recurse);
  672.  
  673. /**
  674.  * Lock a pool
  675.  * @param pool The pool to lock
  676.  * @param flag  The flag
  677.  */
  678. APR_DECLARE(void) apr_pool_lock(apr_pool_t *pool, int flag);
  679.  
  680. /* @} */
  681.  
  682. #else /* APR_POOL_DEBUG or DOXYGEN */
  683.  
  684. #ifdef apr_pool_join
  685. #undef apr_pool_join
  686. #endif
  687. #define apr_pool_join(a,b)
  688.  
  689. #ifdef apr_pool_lock
  690. #undef apr_pool_lock
  691. #endif
  692. #define apr_pool_lock(pool, lock)
  693.  
  694. #endif /* APR_POOL_DEBUG or DOXYGEN */
  695.  
  696. /** @} */
  697.  
  698. #ifdef __cplusplus
  699. }
  700. #endif
  701.  
  702. #endif /* !APR_POOLS_H */
  703.